package com.neuedu.common.domain.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

@Getter
public enum WebSocketEnum {
    /**
     * 上线
     */
    TO_ONLINE("1", "上线"),

    /**
     * 群发
     */
    SEND_GROUP("-2", "群发"),

    /**
     * 下线
     */
    TO_OFFLINE("0", "下线"),

    /**
     * 私聊
     */
    SEND_ONLY("-1", "单发"),
    /**
     *  单发给服务器
     */
    SEND_ONLY_TO_SERVER("-3", "单发给服务器"),
    ;


    WebSocketEnum(String code, String value) {
        this.code = code;
        this.value = value;
    }

    private final String code;

    private final String value;

    public static String getValue(String code) {
        String name = "";
        for (WebSocketEnum dif : values()) {
            if (dif.getCode().equals(code)) {
                name = dif.value;
                break;
            }
        }
        return name;
    }

    public static WebSocketEnum getByValue(String value) {
        if (StrUtil.isBlank(value)) {
            return null;
        }
        for (WebSocketEnum item : WebSocketEnum.values()) {
            if (item.getValue().equals(value)) {
                return item;
            }
        }

        return null;
    }

    public static WebSocketEnum getByCode(String code) {
        if (StrUtil.isBlank(code)) {
            return null;
        }
        for (WebSocketEnum item : WebSocketEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }

}
